/* Copyright 2023-2024
 * Distributed under the terms of the MIT License.
 */


#include <asm_defs.h>


/* int __siglongjmp(jmp_buf buffer, int value) */
FUNCTION(siglongjmp):
FUNCTION(longjmp):
FUNCTION(_longjmp):
	/* 恢复通用寄存器 */
	ld.d $ra,   0*8($a0)
	ld.d $s0,   1*8($a0)
	ld.d $s1,   2*8($a0)
	ld.d $s2,   3*8($a0)
	ld.d $s3,   4*8($a0)
	ld.d $s4,   5*8($a0)
	ld.d $s5,   6*8($a0)
	ld.d $s6,   7*8($a0)
	ld.d $s7,   8*8($a0)
	ld.d $s8,   9*8($a0)
	ld.d $fp,  10*8($a0)
	ld.d $sp,  11*8($a0)

	/* 恢复FPU寄存器 */
	fld.d $f0,  12*8($a0)
	fld.d $f1,  13*8($a0)
	fld.d $f2,  14*8($a0)
	fld.d $f3,  15*8($a0)
	fld.d $f4,  16*8($a0)
	fld.d $f5,  17*8($a0)
	fld.d $f6,  18*8($a0)
	fld.d $f7,  19*8($a0)
	fld.d $f8,  20*8($a0)
	fld.d $f9,  21*8($a0)
	fld.d $f10, 22*8($a0)
	fld.d $f11, 23*8($a0)
	fld.d $f12, 24*8($a0)
	fld.d $f13, 25*8($a0)
	fld.d $f14, 26*8($a0)
	fld.d $f15, 27*8($a0)
	fld.d $f16, 28*8($a0)
	fld.d $f17, 29*8($a0)
	fld.d $f18, 30*8($a0)
	fld.d $f19, 31*8($a0)
	fld.d $f20, 32*8($a0)
	fld.d $f21, 33*8($a0)
	fld.d $f22, 34*8($a0)
	fld.d $f23, 35*8($a0)
	fld.d $f24, 36*8($a0)
	fld.d $f25, 37*8($a0)
	fld.d $f26, 38*8($a0)
	fld.d $f27, 39*8($a0)
	fld.d $f28, 40*8($a0)
	fld.d $f29, 41*8($a0)
	fld.d $f30, 42*8($a0)
	fld.d $f31, 43*8($a0)

	/* 恢复FCSR寄存器 */
	ld.d $t0,  44*8($a0)
	movgr2fcsr $r0, $t0

	tail __longjmp_return
FUNCTION_END(siglongjmp)
FUNCTION_END(longjmp)
FUNCTION_END(_longjmp)

#pragma weak longjmp=siglongjmp